package com.daiqile.myinterest.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.daiqile.myinterest.R;
import com.daiqile.myinterest.customview.ObservableScrollView;

import butterknife.BindView;
import butterknife.ButterKnife;

public class ScrollNextActivity extends AppCompatActivity implements ObservableScrollView.OnObservableScrollViewScrollChanged {

    @BindView(R.id.tv_topView)
    TextView tvTopView;
    @BindView(R.id.tv_endView)
    LinearLayout tvEndView;
    @BindView(R.id.o_scrollView)
    ObservableScrollView oScrollView;
    @BindView(R.id.ll_parent)
    LinearLayout llParent;
    @BindView(R.id.tv_topViewone)
    TextView tvTopViewone;
    @BindView(R.id.tv_endViewone)
    TextView tvEndViewone;
    @BindView(R.id.ll_other)
    LinearLayout llOther;
    @BindView(R.id.oo_scroll)
    ObservableScrollView ooScroll;
    private int topHeight;
    private int endHeight;
    private int llHeight;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_scroll_next);
        ButterKnife.bind(this);
        oScrollView.setOnObservableScrollViewScrollChanged(this);

    }

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
        if (hasFocus) {
            topHeight = tvTopViewone.getHeight();
            endHeight = tvEndViewone.getHeight();
            llHeight = llOther.getHeight();
            Log.d("topHeight", String.valueOf(topHeight));
            Log.d("endHeight", String.valueOf(endHeight));
            Log.d("llHeight", String.valueOf(llHeight));
        }

    }

    @Override
    public void onObservableScrollViewScrollChanged(int l, int t, int oldl, int oldt) {
        if (t > 0 && t < topHeight) {
            tvTopView.setVisibility(View.VISIBLE);
            tvEndView.setVisibility(View.VISIBLE);
            tvTopView.setY(-(topHeight - t));
            tvEndView.setY(llHeight - t);

        } else if (t >= topHeight && t <= llHeight-2*topHeight) {
            tvTopView.setVisibility(View.VISIBLE);
            tvEndView.setVisibility(View.VISIBLE);
            tvEndView.setY(llHeight - t);
        } else if (t > llHeight-2*topHeight ) {
            tvTopView.setVisibility(View.VISIBLE);
            tvEndView.setVisibility(View.VISIBLE);
        }
    }
}
